#!/bin/bash
# $Id: cp-slackware-sets.sh 837 2011-01-06 21:27:26Z ant_code $

wd="`pwd`"
. $wd/env


if [ "$UID" != "0" ]; then
	echo "ERROR: must run as root"
	exit 1
fi

echo ""
echo " For Slackware $slackware_version"
echo ""
echo " This script will copy all packages that appear listed in:  "
echo " 		./files/installcd-initrd/Hurricane/files/packages/pkglist/default "
echo ""
echo " To: ./cdtree/slackware "
echo ""
if [ ! "$sets_location" ]; then
	echo " Enter path to where the original slackware sets"
	echo -n " 	 are located: "
	read sets_location
fi

if [ ! -d "$sets_location" ]; then
	echo " It does not exist or is not a directory, exiting..."
	exit 1
fi
	
if [ -d $wd/files/installcd-initrd/Hurricane/files/packages/pkglist/default ]; then

	if [ ${slackware_arch} = x86_64 ]; then
		slk_dir="slackware64-${slackware_version}"
	else
		slk_dir="slackware-${slackware_version}"
	fi
	mkdir -p $wd/cdtree/$slk_dir
	t="$wd/files/installcd-initrd/Hurricane/files/packages/pkglist/default"
	cd $wd/cdtree/$slk_dir
	for f in `ls $t`; do
		echo "$f ..."
		for p in `cat $t/$f`;do
			mkdir -p `dirname $p`
			# match exclude
			for e in $exclude_slk_pkg ; do
				[ "`echo $p|grep $e`" ] && \
				{ echo "Excluding: $p, continuing ...";
				continue; }
			done
			cp -ruf ${sets_location}/$p `dirname $p` 2>/dev/null
		done
	done

	cd $wd/cdtree/$slk_dir
	md5sum */* > CHECKSUMS.md5
	
	cd $wd
	echo " Done. "
fi
